import { computed, ref } from 'vue'

export const usePagination = (total, pageSize = 10, page = 1, options) => {
    let cPage = ref(page)
    let cPageSize = ref(pageSize)

    const pagination = computed(() => {
        return {
            total: total.value,
            current: cPage.value,
            pageSize,
            ...options
        }
    })

    const onPageChange = (page, pageSize) => {
        cPage.value = page
        cPageSize.value = pageSize
    }

    return {
        page: cPage,
        pageSize: cPageSize,
        pagination,
        onPageChange
    }
}